package com.csu54sher.basereservation.controller;

import com.csu54sher.basereservation.common.ApiResponse;
import com.csu54sher.basereservation.dto.CommentSubmitDTO;
import com.csu54sher.basereservation.service.ICommentService;
import com.csu54sher.basereservation.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评价表 前端控制器
 * </p>
 *
 * @author csu54sher
 * @since 2025-10-19
 */
@RestController
public class CommentController {

    @Autowired
    private ICommentService commentService;

    /**
     * 评价
     * @param reservationId 预约ID
     * @param commentSubmitDTO 评价内容
     * @return
     */
    @PostMapping("/comment/{reservationId}")
    public ApiResponse comment(@PathVariable Integer reservationId,
                               @RequestBody CommentSubmitDTO commentSubmitDTO) {
        commentService.comment(reservationId, commentSubmitDTO);
        return ApiResponse.success();
    }

    /**
     * 获取基地评价
     * @param baseId
     * @return
     */
    @GetMapping("/admin/comment/{baseId}")
    public ApiResponse<List<CommentVO>> getCommentByBaseId(@PathVariable Integer baseId){
        List<CommentVO> commentVOList = commentService.getCommentByBaseId(baseId);
        return ApiResponse.success(commentVOList);
    }

    /**
     * 获取预约评价
     * @param reservationId
     * @return
     */
    @GetMapping("/admin/comment/{reservationId}")
    public ApiResponse<List<CommentVO>> getCommentByReservationId(@PathVariable Integer reservationId){
        List<CommentVO> commentVOList = commentService.getCommentByReservationId(reservationId);
        return ApiResponse.success(commentVOList);
    }



    @GetMapping("/admin/comment")
    public ApiResponse<List<CommentVO>> getComments(){
        List<CommentVO> commentVOList = commentService.getComments();
        return ApiResponse.success(commentVOList);
    }
}
